//
//  ContactModel.m
//  WeCommunity
//
//  Created by mac on 2017/6/15.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "ContactModel.h"

@implementation ContactModel

+(ContactModel *)setValueFormObject:(id)object
{
    ContactModel * model = [ContactModel new];
    //base
    model.userName = [object objectForKey:@"userName"];
    model.sessionToken = [object objectForKey:@"sessionToken"];
    model.objectId = [object objectForKey:@"objectId"];
    //custom
    model.nickName = [object objectForKey:@"nickName"];
    model.WXUserName = [object objectForKey:@"WXUserName"];
    model.sex = [object objectForKey:@"sex"];
    model.userIsAdmin = [[object objectForKey:@"userIsAdmin"] boolValue];
    model.coins = [object objectForKey:@"coins"];//积分
    model.usedCoins = [object objectForKey:@"usedCoins"];//已使用积分
    
    AVFile * file = [object objectForKey:@"headImage"];
    if (![file isEqual: [NSNull null]]  && file.url.length > 0) {
        model.headImage = file.url;
    }
    return model;
}

-(NSString *)userName
{
    if (!_userName) {
        _userName = @"";
    }
    return _userName;
}
-(NSString *)password
{
    if (!_password) {
        _password = @"";
    }
    return _password;
}
-(NSString *)nickName
{
    if (!_nickName) {
        _nickName = @"";
    }
    return _nickName;
}

-(NSString *)WXUserName
{
    if (!_WXUserName) {
        _WXUserName = @"";
    }
    return _WXUserName;
}
-(NSString *)sex
{
    if (!_sex) {
        _sex = @"0";
    }
    return _sex;
}

-(NSString *)sexString
{
    if ([self.sex integerValue] == 1) {
        _sexString = KNSLocal(@"Sex_Men");
    }else if ([self.sex integerValue] == 2) {
        _sexString = KNSLocal(@"Sex_Women");;
    }else {
        _sexString = @"";
    }
    return _sexString;
}

-(NSString *)headImage
{
    if (!_headImage) {
        _headImage = @"";
    }
    return _headImage;
}

-(NSInteger)userVipLevel
{
    //    1-100 微商萌新
    //    100-300  微商能手
    //    300-600  微商达人
    //    600-1000  微商大神
    if (self.usedCoins >= [NSNumber numberWithInt:1] && self.usedCoins < [NSNumber numberWithInt:100]) {
        _userVipLevel = 1;
    }else if (self.usedCoins >= [NSNumber numberWithInt:100] && self.usedCoins < [NSNumber numberWithInt:300]){
        _userVipLevel = 2;
    }else if (self.usedCoins >= [NSNumber numberWithInt:300] && self.usedCoins < [NSNumber numberWithInt:600]){
        _userVipLevel = 3;
    }else if (self.usedCoins >= [NSNumber numberWithInt:600]){
        _userVipLevel = 4;
    }else{
        _userVipLevel = 0;
    }
    
    return _userVipLevel;
}
-(NSString *)userVipLevelStr
{

    if (self.userVipLevel == 1) {
        _userVipLevelStr = @"微商萌新";
    }else if (self.userVipLevel == 2){
        _userVipLevelStr = @"微商能手";
    }else if (self.userVipLevel == 3){
        _userVipLevelStr = @"微商达人";
    }else if (self.userVipLevel == 4){
        _userVipLevelStr = @"微商大神";
    }else{
        _userVipLevelStr = @"";
    }
    
    return _userVipLevelStr;
}

-(UIImage *)userVipLevelImage
{
    if (self.userVipLevel == 1) {
        _userVipLevelImage = [UIImage imageNamed:@"vip 1"];
    }else if (self.userVipLevel == 2){
        _userVipLevelImage = [UIImage imageNamed:@"vip 2"];
    }else if (self.userVipLevel == 3){
        _userVipLevelImage = [UIImage imageNamed:@"vip 3"];
    }else if (self.userVipLevel == 4){
        _userVipLevelImage = [UIImage imageNamed:@"vip 4"];
    }else{
        _userVipLevelImage = nil;
    }
    
    return _userVipLevelImage;
}





@end
